<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        // Date()日期对象
        var date = new Date();
       /*  console.log(date); // 输出当前时间
        // 参数常用写法
        var date2 = new Date('2022-3-27 8:8:8');
        console.log(date2); 
        var date3 = new Date(2022, 10, 27);
        console.log(date3);
        console.log(date.getFullYear());
        console.log(date.getMonth() + 1);
        console.log(date.getDay());
        console.log(date.getDate());
        // 格式化输出年月日
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var dates = date.getDate();
        var arr = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
        var day = arr[date.getDay()];
        var hour = date.getHours();
        var minute = date.getMinutes();
        var second = date.getSeconds();
        console.log(year + '年' + month + '月' + dates + '日' + day + hour + '点' + minute + '分' + second + '秒');
        // 格式化输出时分秒
        function getTime() {
            var time = new Date();
            var h = time.getHours();
            h = h < 10 ? '0' + h : h;
            var m = time.getMinutes();
            m = m < 10 ? '0' + m : m;
            var s = time.getSeconds();
            s = s < 10 ? '0' + s : s;
            return h + ':' + m + ':' + s;
        }
        console.log(getTime()); */
        // 时间戳 距离1970年1月1日过了多少毫秒
        // 1.通过valueOf() getTime()
        console.log(date.valueOf());
        console.log(date.getTime());
     /*    // 2.简单的写法
        var date1 = +new Date(); //返回的就是总的毫秒
        console.log(date1);
        // 3.H5 新增用法获得总的毫秒数
        console.log(Date.now());
        // 倒计时
        function countDown(time) {
            var nowTime = +new Date();
            var inputTime = +new Date(time);
            var times = (inputTime - nowTime)/1000;// 剩余时间总的毫秒数
            var d = parseInt(times / 60 / 60 / 24);
            var h = parseInt(times / 60 / 60 % 24);
            var m = parseInt(times / 60 % 60);
            var s = parseInt(times % 60);
            return d + '天' + h + '时' + m + '分' + s + '秒';
        }
        console.log(countDown('2022-8-2 24:00:00'));
 */
    </script>
</head>
<body>
    
</body>
</html>